<?php

namespace App\Admin\Controllers\funds;

use App\Common\statement\CommonStatement;
use App\Models\fund\Rebate;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class RebateController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '返利记录';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Rebate);

        $grid->model()->orderByDesc('id');

        $grid->disableCreateButton();

//         行操作全部关闭
        $grid->disableActions();

        $grid->column('id', __('Id'));
        $grid->column('user_id', __('User id'));
        $grid->column('user.header_img', __('header_img'))
            ->lightbox(['width' => 50, 'height' => 50, 'class' => ['circle', 'thumbnail']]);

        $grid->column('user.name', __('Name'));
        $grid->column('user.phone', __('Phone'));
        $grid->column('relation_user_id', __('Relation user id'));

        $grid->column('RelationUser.header_img', __('header_img'))
            ->lightbox(['width' => 50, 'height' => 50, 'class' => ['circle', 'thumbnail']]);

        $grid->column('RelationUser.name', __('Name'));
        $grid->column('RelationUser.phone', __('Phone'));

//        $grid->column('order_id', __('Order id'));
        $grid->column('type', __('Type'))->display(function ($type){
            return CommonStatement::rebate_type[$type];
        });
        $grid->column('amount', __('Amount'));
        $grid->column('title', __('Title'));
        $grid->column('status', __('Status'))->display(function ($status){
            return CommonStatement::rebate_status[$status];
        });
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Rebate::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('user_id', __('User id'));
        $show->field('relation_user_id', __('Relation user id'));
        $show->field('order_id', __('Order id'));
        $show->field('type', __('Type'));
        $show->field('amount', __('Amount'));
        $show->field('title', __('Title'));
        $show->field('status', __('Status'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Rebate);

        $form->number('user_id', __('User id'));
        $form->number('relation_user_id', __('Relation user id'));
        $form->number('order_id', __('Order id'));
        $form->switch('type', __('Type'));
        $form->decimal('amount', __('Amount'));
        $form->text('title', __('Title'));
        $form->switch('status', __('Status'));

        return $form;
    }
}
